/**
 * 详情对话框
 */
var PageConfigInfoDlg = {
    data: {
        logo: "",
        siteName: "",
        title: "",
        subTitle: "",
        adPic: "",
        copyright: "",
        beian: ""
    }
};

layui.use(['form', 'admin', 'ax','laydate','upload','formSelects'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;



    //普通图片上传
    var upload = layui.upload;
    upload.render({
        elem: '#logoBtn'
        ,accept: 'images'
        ,url: Feng.ctxPath + '/system/uploadoss' //改成您自己的上传接口
        ,done: function(res){
        	Feng.success("上传成功！");
        	var url = res.data.url
        	
        	$("#logoadd").attr("style","display:none;")
        	$("#logoimg").attr("src",url)
        	$("#logo").val(url)
        	$("#logoimg").attr("style","display:block;")
        }
        ,error: function(){
            Feng.error("上传文件失败！");
        }
    });
    
    
    
  //普通图片上传
    var upload2 = layui.upload;
    upload2.render({
        elem: '#adPicBtn'
        ,accept: 'images'
        ,url: Feng.ctxPath + '/system/uploadoss' //改成您自己的上传接口
        ,done: function(res){
        	Feng.success("上传成功！");
        	var url = res.data.url
        	
        	$("#adPicadd").attr("style","display:none;")
        	$("#adPicimg").attr("src",url)
        	$("#adPic").val(url)
        	$("#adPicimg").attr("style","display:block;")
        }
        ,error: function(){
            Feng.error("上传文件失败！");
        }
    });





















    //获取详情信息，填充表单
    var ajax = new $ax(Feng.ctxPath + "/pageConfig/detail");
    var result = ajax.start();
    form.val('pageConfigForm', result.data);
    
    var data = result.data
    
    if(data.logo.length>0){
    	$("#logoadd").attr("style","display:none;")
    	$("#logoimg").attr("src",data.logo)
    	$("#logoimg").attr("style","display:block;")
    }
    
    if(data.adPic.length>0){
    	$("#adPicadd").attr("style","display:none;")
    	$("#adPicimg").attr("src",data.adPic)
    	$("#adPicimg").attr("style","display:block;")
    }

    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var ajax = new $ax(Feng.ctxPath + "/pageConfig/editItem", function (data) {
            Feng.success("更新成功！");
            window.location.href = Feng.ctxPath + '/pageConfig'
        }, function (data) {
            Feng.error("更新失败！" + data.responseJSON.message)
        });
        ajax.set(data.field);
        ajax.start();

        return false;
    });

    $('#cancel').click(function(){
        window.location.href = Feng.ctxPath + '/pageConfig'
    });
});